package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.common.RedisConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 登录控制器
 */
@RestController
@RequestMapping("/mobile/login")
@Slf4j
@Api(tags = "手机端登录接口")
public class MobileLoginController {

    @Autowired
    private MemberService memberService;

    /**
     * 手机验证码登录
     * @param map
     * @return
     */
    @PostMapping("/smsLogin")
    public Result smsLogin(@RequestBody Map map){

        // 获取验证码和手机号
        String validateCode = (String)map.get("validateCode");
        String telephone = (String)map.get("telephone");
//        log.info("登录用户手机号: {},{}", telephone, validateCode);
        //
        Boolean status = memberService.findByTelephone(validateCode,telephone);
        if(status) {
            return new Result(true, MessageConst.LOGIN_SUCCESS);
        }
        return new Result(false,MessageConst.LOGIN_FAIL);
    }
}
